<?php
header("utf-8");
//题目1
class Goods
{
	private $name;
	private $price;
	private $stock;
	function __construct($n,$p,$s)
	{
		$this->name=$n;
		$this->price=$p;
		$this->stock=$s;
	}
	function show_stock()
	{
		echo $this->stock."<br>";
	}
	function in_stock($in_amount)
	{
		$this->stock = $this->stock+$in_amount;
		echo "stock:".$this->stock."<br>";
	}
	function out_stock($out_amount)
	{
		$this->stock=$this->stock-$out_amount;
		if ($this->stock>=0)
			echo "stock:".$this->stock."<br>";
		else
			echo "stock:". 0;
	}
	function __destruct()
	{
		echo "销毁库存"."<br>";
	}
}
class shoes extends Goods
{
	private $discount_rate;
	private $discount_price;
}
$iphone=new Goods("iphone",10000,100);
$iphone->show_stock();
$iphone->in_stock(10);
$iphone->out_stock(100);
echo "<br>";

//题目2
class Fun
{
	function fun1(){
		echo "fun1"."<br>";
	}
	function fun2(){
		echo "fun2"."<br>";
	}
	function fun3(){
		echo "fun3"."<br>";
	}
	function fun4(){
		echo "fun4"."<br>";
	}
}
class MyFun extends Fun
{
	function fun1()
	{
		echo "实现自己的功能"."<br>";
	}
	function fun2()
	{
		echo "fun2"."<br>";
		echo "增加一个功能"."<br>"; 
	}
	function fun3(){}
}
$test2=new MyFun;
$test2-> fun1();
$test2-> fun2();
$test2-> fun3();
$test2-> fun4();
echo "<br>";
//题目3
interface Shape
{
	public function display();
    public function area();
    public function volum();
    public function printname();
}
class Point implements Shape
{
    public $x;
    public $y;

  	function __construct($x1,$y1)
  	{
  		$this->x=$x1;
  		$this->y=$y1;
  	}
  	function display()
  	{
  		echo "x:".$this->x."<br>";
  		echo "y:".$this->y."<br>";
  	}
    public function area()
    {
       	echo "area:". 0 ."<br>";
    }
  
    public function volum()
    {
		echo "volum:". 0 ."<br>";
    }
    public function printname()
    {
    	echo "横坐标为".$this->x."纵坐标为".$this->y."的点"."<br>";
    }
}
$test3=new Point(10,12);
$test3->display();
$test3->area();
$test3->volum();
$test3->printname();
echo "<br>";
//题目4
class Circle extends Point
{
	public $r;
	function __construct($x1,$y1)
  	{
  		$this->r=$x1;
  	}
  	function display()
  	{
  		echo "r:".$this->r."<br>";
  	}
	function area()
    {
    	$area=3.14*$this->r*$this->r;
    	if ($area>0)
         	echo "area:".$area."<br>";
        else
        	echo "area:". 0 ."<br>";
    }
  
    function volum()
    {
      	echo "volum:". 0 ."<br>";
    }
    function printname()
    {
    	echo "半径为".$this->r."的圆<br>";
    }
}
$test4=new Circle(10,0);
$test4->display();
$test4->area();
$test4->volum();
$test4->printname();
echo "<br>";
//题目5
class Cylinder extends circle
{
	private $h;
	function __construct($r,$h)
  	{
  		$this->r=$r;
  		$this->h=$h;
  	}
  	function display()
  	{
  		echo "r:".$this->r."<br>";
  		echo "h:".$this->h."<br>";
  	}
	function area()
    {
    	$area=(2*3.14*$this->r*$this->r)+(2*3.14*$this->r*$this->h);
    	if ($area>0)
         	echo "area:".$area."<br>";
        else
        	echo "area:". 0 ."<br>";
    }
  
    function volum()
    {
      	$volum=3.14*$this->r*$this->r*$this->h;
        if ($volum>0)
        	echo "volum:".$volum."<br>";
        else
        	echo "volum:". 0 ."<br>";
    }
    function printname()
    {
    	echo "底面半径为".$this->r."高为".$this->h."的圆柱<br>";
    }
}
$test5=new Cylinder(10,10);
$test5->display();
$test5->area();
$test5->volum();
$test5->printname();
echo "<br>";

//题目6
class trangle implements shape
{
	private $a,$b,$c;
	function __construct($x,$y,$z)
	{
		$this->a=$x;
  		$this->b=$y;
  		$this->c=$z;
	}
	public function display()
	{
		echo "a:".$this->a."<br>";
  		echo "b:".$this->b."<br>";
  		echo "c:".$this->c."<br>";
	}
    public function area()
    {
    	$p=($this->a+$this->b+$this->c)/2;
    	$area=sqrt($p*($p-$this->a)*($p-$this->b)*($p-$this->c));
    	if ($area>0)
         	echo "area:".$area."<br>";
        else
        	echo "area:". 0 ."<br>";
    }
    public function volum()
    {
    	echo "volum:". 0 ."<br>";
    }
    public function printname()
    {
    	echo "三条边的边长分别为".$this->a.",".$this->b.",".$this->c."的三角形"."<br>";
    }
}
$test6=new trangle(3,4,5);
$test6->display();
$test6->area();
$test6->volum();
$test6->printname();
echo "<br>";
//题目7
class Square implements shape
{
	private $a;
	function __construct($x)
	{
		$this->a=$x;
	}
	public function display()
	{
		echo "a:".$this->a."<br>";
	}
    public function area()
    {
    	$area=$this->a*$this->a;
    	if ($area>0)
         	echo "area:".$area."<br>";
        else
        	echo "area:". 0 ."<br>";
    }
    public function volum()
    {
    	echo "volum:". 0 ."<br>";
    }
    public function printname()
    {
    	$point1=new Point(10,10);
	    $point2=new Point(10-$this->a/2,10+$this->a/2);
    	echo "边长为".$this->a."的正方形"."<br>";
    	echo "中心为:";$point1->printname();
    	echo "有一个顶点为:";$point2->printname();
    }
}
$test7=new Square(10);
$test7->display();
$test7->area();
$test7->volum();
$test7->printname();
echo "<br>";
?>